<template>
  <div class="app-container">
    <SearchForm
      v-show="showSearch"
      v-model="queryParams"
      :options="options.formOps"
      @onQuery="getList"
    >
    </SearchForm>
    <el-row :gutter="10" class="mb8">
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <Table
      ref="table"
      :auto-featch="true"
      :fetch-data="fetchData"
      :options="options.table"
      actionWidth="200"
    >
      <template #default>
        <el-table-column
          label="上传状态"
          align="center"
          width="100"
          prop="reviewDate"
        >
          <template #default="{ row }">
            {{ !row.annexFileUrl ? "未上传" : "已上传" }}
          </template>
        </el-table-column>
      </template>

      <template #actionButton="{ row }">
        <el-button
          type="text"
          :disabled="!row.annexFileUrl"
          @click="handDownload(row)"
          v-hasPermi="['lawRegulationsStandard:edit']"
          >下载</el-button
        >
        <el-button
          type="text"
          @click="handleEdit(row)"
          v-hasPermi="['lawRegulationsStandard:edit']"
          >查看</el-button
        >
      </template></Table
    >
    <DialogVform
      :formJson="formJson"
      ref="dialogVform"
      @onSubmit="onSubmit"
      :slots="['fileSolt']"
      :showBotton="false"
    >
      <template #fileSolt>
        <el-form-item label="文件上传" prop="fileId">
          <FileUpload :limit="1" :fileSize="30" v-model="files"></FileUpload>
        </el-form-item>
      </template>
    </DialogVform>
  </div>
</template>

<script setup>
import Table from "@/components/Table/index.vue";
import SearchForm from "@/components/searchForm/index";
import DialogVform from "@/components/dialogVform/index";
import { apis as APIS } from "@/api/aqsc/flfg copy.js";
import formJson from "./components/options.json";
import { useAsyncData, useFormJson } from "@/views/hooks/useAsyncData.js";
import ImportExcel from "@/components/ImportExcel/index.vue";
import ExportExcel from "@/components/ExportExcel/index.vue";
import FileUpload from "@/components/FileUpload";
const { proxy } = getCurrentInstance();
const ops = useFormJson(formJson, {
  sort: [],
  sortable: [],
});
const options = reactive({
  table: ops,
  formOps: ops.filter((i) =>
    ["docType", "docNumber", "docName"].includes(i.prop)
  ),
});
const showSearch = ref(true);
const dialogVform = ref();
const table = ref();
const plugAdd = () => {
  files.value = [];
};
const plugEdit = (row) => {
  if (row.annexFileId) {
    files.value = [
      {
        name: row.annexFileName,
        id: row.annexFileId,
        url: row.annexFileUrl,
      },
    ];
  } else {
    files.value = [];
  }
};
const {
  onSubmit,
  fetchData,
  handleAdd,
  handleEdit,
  getList,
  handleDel,
  queryParams,

  form,
} = useAsyncData({
  APIS,
  formJson,
  dialogVform,
  table,
  proxy,
  plugAdd,
  plugEdit,
});
const files = ref([]);
watch(
  () => files,
  (newData) => {
    if (newData.value.length === 0) {
      form.value.annexFileName = "";
      form.value.annexFileId = "";
      form.value.annexFileUrl = "";
    } else {
      form.value.annexFileName = newData.value[0].name;
      form.value.annexFileId = newData.value[0].id;
      form.value.annexFileUrl = newData.value[0].url;
    }
  },
  {
    deep: true,
  }
);
const handDownload = (row) => {
  window.downLoadFile(row.annexFileUrl, row.annexFileName);
};
const handleFeizhi = (row) => {
  APIS.update({
    ...row,
    enableStatus: "2",
  });
};
</script>

<style lang="scss" scoped></style>
